// pages/trainingVideo/searchRes/index.js
import {
    kbVideoList,
    kbDocList
} from '../../../apis/index';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        placeHolederstr:'',
        list:[],
        type:1,
        pageNum:1,
        loading:false,
        finshed:false,
    },
    //获取视频列表projectid
    GetkbVideoList(){
        let pageNum = this.data.pageNum
        wx.showLoading({
            title: '加载中...',
            mask: true
            });
        this.setData({
            loading:true
        })
        kbVideoList({pageNum,pageSize:'20',type:this.type,videoTitle:this.str,orderByColumn:'publishTime'}).then(res=>{
            wx.hideLoading()
            if(res.data.rows&& res.data.rows.length>0){
                let list = this.data.list.concat(res.data.rows) 
                let ctr = false
                if(list.length>=res.data.total ){
                    ctr=true
                }
                this.setData({
                    pageNum:pageNum+=1,
                    finshed:ctr,
                    loading:false,
                    list
                })          
            }

        })
    },
    //获取文章列表
    GetkbDocList(){
        let pageNum = this.data.pageNum
        wx.showLoading({
            title: '加载中...',
            mask: true
            });
        this.setData({
            loading:true
        })
        kbDocList({pageNum,pageSize:'20',docTitle:this.str,orderByColumn:'publishTime'}).then(res=>{
            wx.hideLoading()
            if(res.data.rows){
                let list = this.data.list.concat(res.data.rows) 
                let ctr = false
                if(list.length>=res.data.total ){
                    ctr=true
                }
                this.setData({
                    pageNum:pageNum+=1,
                    finshed:ctr,
                    list
                })                
            }
            this.setData({
                loading:false,
            })

        })
    },
    searchFun(e){
        let str =   e.detail.value
        this.str = str
        if(!str)return
        if(this.type==1 ||this.type==2 ){
            this.GetkbVideoList()
        }else{
            this.GetkbDocList()
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log(options)
        let {type} = options 
        let str = ''
        if(type ==1 || type ==2){
            str = '输入视频标题搜索'
        }else{
            str = '输入资料关键词搜索'
        }
        this.type = type
        this.setData({
            type,
            placeHolederstr:str
        })

    },
    gotoVD(e){
        // console.log(e)
        let vid = e.target.dataset.vid || e.currentTarget.dataset.vid 
        wx.navigateTo({
          url: '/pages/trainingVideo/trainingVideoDetail/index?vid=' + vid 
        })
    },
    gotoZD(e){
        let vid = e.target.dataset.vid || e.currentTarget.dataset.vid 
        wx.navigateTo({
          url: '/pages/trainingVideo/consultationDetail/index?vid=' + vid,
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        if(!this.data.finshed && !this.data.loading){
            if(this.type==1 ||this.type==2 ){
                this.GetkbVideoList()
            }else{
                this.GetkbDocList()
            }
        }
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})